package com.bc.commoncore.util;

import org.apache.commons.lang.StringUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 常用数据格式验证
 * Created by lianzerong on 2018/8/21.
 */
public class DataUtils {

    /**
     * 邮箱格式验证
     * @param email
     * @return
     */
    public static boolean isEmail(String email) {
        String check = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{1,}$";
        return  match(check, email);
    }

    private static boolean match(String check, String input) {
        if (StringUtils.isEmpty(check) || StringUtils.isEmpty(input)) {
            return false;
        }
        Pattern regex = Pattern.compile(check);
        Matcher matcher = regex.matcher(input);
        return  matcher.matches();
    }
}
